//
//  ViewController.m
//  团购网
//
//  Created by song on 15/1/12.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "ViewController.h"
#import "MyTg.h"
#import "TgCell.h"
#import "MyTgFooterView.h"
#import "MyTgHeadView.h"

@interface ViewController ()<UITableViewDataSource ,MyFooterViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ViewController


-(NSMutableArray *)tgs
{
    
    if(_tgs ==nil)
    {
        NSString *path =[[NSBundle mainBundle]pathForResource:@"tgs.plist" ofType:nil];
        
        NSArray *dicarray =[NSArray arrayWithContentsOfFile:path];
        
        NSMutableArray *tgarray =[NSMutableArray array];
        
        for(NSDictionary *dict in dicarray)
        {
            MyTg *tg = [MyTg tgWithDict:dict];
            [tgarray addObject:tg];
        }
        
        _tgs = tgarray;
    }
    return _tgs;
    
}

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tgs.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID=@"tg";
    
    TgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell ==nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"tgcellview" owner:nil options:nil] lastObject ];
    }
  
    cell.tg = self.tgs[indexPath.row];

    return  cell;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 90;
    
    MyTgFooterView *footer = [MyTgFooterView footView];
    footer.delegate = self;
    self.tableView.tableFooterView = footer;
    
    MyTgHeadView *head =[MyTgHeadView tgHeadView];
    self.tableView.tableHeaderView = head;
    
}


-(void)loadingMoreData
{
    MyTg *tg =[[MyTg alloc]init];
    tg.icon =@"ad_01";
    tg.title = @"hello word";
    tg.price =@"12";
    tg.buyCount=@"23";
    [self.tgs addObject:tg];
    [self.tableView reloadData];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

@end
